function quickSort(arr) {
    if (arr.length <= 1) {
        return arr
    } else {
        let pivotIndex = Math.floor(arr.length / 2);
        let pivot = arr.splice(pivotIndex, 1)[0];
        let left = [];
        let right = [];
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] <= pivot) {
                left.push(arr[i])
            } else {
                right.push(arr[i])
            }
        }
        return quickSort(left).concat([pivot], quickSort(right))
    }
}

// 找基准，把小的放在基准左边，大的放在基准右边
// 时间复杂度nlogn
arr = [1, 2, 6, 3, 4, 8];
console.log(quickSort(arr));